function bindEvent(){

	//阻止浏览器默认右键点击事件
	$("#canvas").bind("contextmenu", function(){
		return false;
	})


	$("#canvas").click(function(){
		//console.log('click');
		//标准的获取鼠标点击相对于canvas画布的坐标公式
		var x = event.pageX - canvas.getBoundingClientRect().left;
		var y = event.pageY - canvas.getBoundingClientRect().top;
		//选中单元格
		var cell = getWorkbookSheetCellByXY(currentSheet,x,y);
		var cellLength = Object.keys(cell).length;
		if(cellLength > 0){
			var cellkey = 'cell_' + cell.row + '_' + cell.col;
			selectedcells[cellkey] = cell;
			//highlightedSelectedCells();
			reloadWorkBook();
			//获取单元格的属性及值、值类型
			var selcelldata = getCellData(currentSheet,cellkey);
			if(selcelldata){
				$("#cellinput").val(selcelldata);
			}else{
				$("#cellinput").val('');
			}
			var selcelldatatype = getCellDatatype(currentSheet,cellkey);
			//console.log(selcelldatatype);
			if(selcelldatatype){
				$("#celldatatype").val(selcelldatatype);
			}

			var fontstyle = getCellFontStyle(currentSheet,cellkey);
			//console.log(fontstyle);
			if(fontstyle){
				var fontarray = fontstyle.split(" ");
				//console.log(fontarray);
				$("#selFontFamily").val(fontarray[4]);
				$("#selFontSize").val(fontarray[3]);
				if(fontarray[2] == 'bold'){
					$("#fontweightbtn").addClass('active');
				}else{
					$("#fontweightbtn").removeClass('active');
				}
			}
		}
		

		var editValue = $("#celledit")[0].innerText;
		//console.log(editValue);
		if(editValue && editValue != ''){
			var editcellkey = 'cell_' + currentRow + '_' + currentCol;
			//把数值赋予当前选中的单元格
			setCellData(currentSheet,editcellkey,editValue);
			reloadWorkBook();
			$("#celledit")[0].innerText = '';
			$("#celledit").hide();
		}

		//如果不是调整行列大小
		
		if(clickselected){
			//selectedcells = {};
			selectedrows = {};
			selectedcols = {};
			var selcol = getCurrentColByXY(currentSheet,x,y);
			var selrow = getCurrentRowByXY(currentSheet,x,y);
			
			if(selrow != null){
				selectedrows[selrow] = selrow;
			}
			if(selcol != null){
				selectedcols[selcol] = selcol;
			}
			//highlightedSelectedRowsORCols();
			reloadWorkBook();
			clickselected = false;
		}
		
	});

	$("#canvas").dblclick(function(){
		//标准的获取鼠标点击相对于canvas画布的坐标公式
		var x = event.pageX - canvas.getBoundingClientRect().left;
		var y = event.pageY - canvas.getBoundingClientRect().top;
		
		var cell = getWorkbookSheetCellByXY(currentSheet,x,y)
		//console.log(cell);
		currentCol = cell.col;
		currentRow = cell.row;
		$("#celledit").show();
		$("#celledit").css("left",cell.x + canvas.getBoundingClientRect().left);
		$("#celledit").css("top",cell.y + canvas.getBoundingClientRect().top);
		$("#celledit").css("width",cell.width);
		$("#celledit").css("height",cell.height);
		$("#celledit").css("line-height",cell.height+'px');
		$("#celledit")[0].innerText = getCellData(currentSheet,'cell_'+cell.row+'_'+cell.col);
						
	});


	$("#canvas").mousemove(function (){
		
		//标准的获取鼠标点击相对于canvas画布的坐标公式
		var x = event.pageX - canvas.getBoundingClientRect().left;
		var y = event.pageY - canvas.getBoundingClientRect().top;

		var cell = getWorkbookSheetCellByXY(currentSheet,x,y);
		drawMouseMoveInfo(canvaswidth,canvasheight,x,y,cell.row,cell.col);
		
		if(bDrap){
			//var cell = getWorkbookSheetCellByXY(currentSheet,x,y)
			//console.log(cell);
			//var cellkey = 'cell_' + cell.row + '_' + cell.col;
			//selectedcells[cellkey] = cell;
		}

		//判断是否选择了边框
		if(!cellresize){
			var resizeWidth = isResizeCellWidth(currentSheet,x,y);
			if(!resizeWidth){
				isResizeCellHeight(currentSheet,x,y);
			}
		}
		
	});

	var downx = 0;
	var downy = 0;
	var startDrapCell = {};
	var endDrapCell = {};

	$("#canvas").mousedown(function (){
		//console.log('mousedown');
		//标准的获取鼠标点击相对于canvas画布的坐标公式
		var x = event.pageX - canvas.getBoundingClientRect().left;
		var y = event.pageY - canvas.getBoundingClientRect().top;
		bDrap = true;
		clearSelectedCells();

		startDrapCell = {};
		startDrapCell = getWorkbookSheetCellByXY(currentSheet,x,y)

		if(selectedCol != null || selectedRow != null){
			cellresize = true;
			downx = x;
			downy = y;
		}
	});

	$("#canvas").mouseup(function (){
		var x = event.pageX - canvas.getBoundingClientRect().left;
		var y = event.pageY - canvas.getBoundingClientRect().top;

		if(cellresize){
			var offset_x = x - downx;
			var offset_y = y - downy;
			if(selectedCol != null){
				var cellW = getColWidth(currentSheet,'col_' + selectedCol);
				changeColWidth(currentSheet,'col_' + selectedCol,cellW+offset_x);
				selectedCol = null;
			}

			if(selectedRow != null){
				var cellH = getRowHeight(currentSheet,'row_' + selectedRow);
				changeRowHeight(currentSheet,'row_' + selectedRow,cellH+offset_y);
				selectedRow = null;
			}
			cellresize = false;
			reloadWorkBook();
		}
		
		if(bDrap){
			endDrapCell = {};
			endDrapCell = getWorkbookSheetCellByXY(currentSheet,x,y);
			createDrapSelectedCell();
			highlightedSelectedCells();
			bDrap = false;
			startDrapCell = {};
			endDrapCell = {};
		}
	});

	
	function createDrapSelectedCell(){
		//console.log(startDrapCell);
		//console.log(endDrapCell);
		var startDrapCellLength = Object.keys(startDrapCell).length;
		var endDrapCellLength = Object.keys(endDrapCell).length;
		if(startDrapCell && startDrapCellLength > 0 && endDrapCell && endDrapCellLength > 0){
			var startcellkey = 'cell_' + startDrapCell.row + '_' + startDrapCell.col;
			selectedcells[startcellkey] = startDrapCell;

			var endcellkey = 'cell_' + endDrapCell.row + '_' + endDrapCell.col;
			selectedcells[endcellkey] = endDrapCell;
			//console.log(selectedcells);

			for (var col = startDrapCell.col; col <= endDrapCell.col; col++) {
				for (var row = startDrapCell.row; row <= endDrapCell.row; row++) {
					var cellkey = 'cell_' + row + '_' + col;
					selectedcells[cellkey] = getCanvasCellByCellkey(cellkey);
				}	
			}

		}
	}

}